import axios from 'axios';

const service = axios.create({
  baseURL: 'http://localhost:5000/api' // url = base url + request url
})

service.interceptors.response.use(
    response => {
      if (response.code !== '200') {
        return response.data;
      } else {
        return response;
      }
    },
    error => {
         console.log(error)
      return Promise.reject();
    }
);


// request 拦截器
// 可以自请求发送前对请求做一些处理
// 比如统一加token，对请求参数统一加密
service.interceptors.request.use(config => {
  config.headers['x-auth-token'] =  $.db.get('token');
  return config
}, error => {
  return Promise.reject(error)
});
export default service